//
//  SXPFooterView.swift
//  weibo
//
//  Created by shixinPeng on 16/3/1.
//  Copyright © 2016年 shixinPeng. All rights reserved.
//

import UIKit


class SXPFooterView: UIView {
    
    var footerViewModel:SXPstatusesViewModel?{
        didSet{
            retweetButton.setTitle(footerViewModel?.reposts, forState: .Normal)
            commentsButton.setTitle(footerViewModel?.comments, forState: .Normal)
            goodButton.setTitle(footerViewModel?.attitudes, forState: .Normal)
            
        }
    }
    
    ///MARK:第一步:重写初始化方法
    override init(frame: CGRect) {
        super.init(frame: frame)
        setUpUI()
    }

     required init?(coder aDecoder: NSCoder) {
         fatalError("init(coder:) has not been implemented")
     }
    ///MARK:第二部:私有方法,添加控件和设置约束
    private func setUpUI() {
        //添加控件
        addSubview(retweetButton)
        addSubview(commentsButton)
        addSubview(goodButton)
        //获取线条
        let lineLeft = getLine()
        let lineRight = getLine()
        
        addSubview(lineLeft)
        addSubview(lineRight)
        //添加点击事件
        retweetButton.addTarget(self, action: "footerRetweetBtnClick", forControlEvents: .TouchUpInside)
        
        //设置约束
        retweetButton.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(self.snp_left)
            make.top.equalTo(self.snp_top)
            make.bottom.equalTo(self.snp_bottom)
            //关键的约束
            make.width.equalTo(commentsButton.snp_width)
        }
        goodButton.snp_makeConstraints { (make) -> Void in
            make.right.equalTo(self.snp_right)
            make.top.equalTo(self.snp_top)
            make.bottom.equalTo(self.snp_bottom)
            //关键约束
            make.width.equalTo(commentsButton.snp_width)
        }
        commentsButton.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(retweetButton.snp_right)
            make.right.equalTo(goodButton.snp_left)
            make.top.equalTo(self.snp_top)
            make.bottom.equalTo(self.snp_bottom)
        }
        lineLeft.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(retweetButton.snp_right)
            make.centerY.equalTo(retweetButton.snp_centerY)
        }
        lineRight.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(commentsButton.snp_right)
            make.centerY.equalTo(commentsButton.snp_centerY)
        }
        
        
    }
    //转发的响应事件
    @objc private func footerRetweetBtnClick(){
        //利用响应者链条进行信息传递
        
        //获取目标控制器
        let ret = SXPretweetPublishVC()
        
        //隐藏tarbar
        ret.hidesBottomBarWhenPushed = true
        
        //控制器跳转
        navController()?.pushViewController(ret, animated: true)
        
        
        
    }
    
    
    
    ///MARK:第三步:懒加载
    ///转发按钮
    private lazy var retweetButton:UIButton = {
    let btn = UIButton(type: .Custom)
        
        btn.setImage(UIImage(named: "timeline_icon_retweet"), forState: .Normal)
        
        btn.setTitle("转发", forState: .Normal)
        
        btn.setTitleColor(UIColor(white: 0.5, alpha: 1), forState: .Normal)
        
    return btn
    }()
    /// 评论按钮
    private lazy var commentsButton:UIButton = {
        let btn = UIButton(type: .Custom)
        
        btn.setImage(UIImage(named: "timeline_icon_comment"), forState: .Normal)
        
        btn.setTitle("评论", forState: .Normal)
        
        btn.setTitleColor(UIColor(white: 0.5, alpha: 1), forState: .Normal)
        
        return btn
    }()
    ///点赞按钮 goodButton
    private lazy var goodButton: UIButton = {
    let btn = UIButton(type: .Custom)
        
        btn.setImage(UIImage(named: "timeline_icon_like"), forState: .Normal)
        
        btn.setTitle("赞", forState: .Normal)
        
        btn.setTitleColor(UIColor(white: 0.5, alpha: 1), forState: .Normal)
        
    return btn
    }()
    ///  获取一条线段的方法
    private func getLine() -> UIImageView{
        let img = UIImageView()
        
        img.image = UIImage(named: "timeline_card_bottom_line_highlighted")
        
        return img
    }

}
